package com.turtle3d.visualizator;

import javax.media.j3d.Shape3D;
import javax.vecmath.Point3f;

import com.sun.j3d.utils.geometry.GeometryInfo;
import com.sun.j3d.utils.geometry.NormalGenerator;

public class MyBox extends Shape3D {
	
	public MyBox(float side){
						
		float a = side/2f;
		
		Point3f lower[] = new Point3f[4];
		Point3f upper[] = new Point3f[4];
		
		lower[0] = new Point3f(-a,-a,-a);
		upper[0] = new Point3f(-a,-a,a);
		
		lower[1] =new Point3f(a, -a, -a);
		upper[1] =new Point3f(a, -a, a);
		
		lower[2] =new Point3f(a, a, -a);
		upper[2] =new Point3f(a, a, a);
		
		lower[3] =new Point3f(-a, a, -a);
		upper[3] =new Point3f(-a, a, a);				
				
		//per polygon
		Point3f points[] = new Point3f[24];
		points[0] = lower[3];
		points[1] = lower[2];
		points[2] = lower[1];
		points[3] = lower[0];
		
		points[4] = lower[1];
		points[5] = upper[1];
		points[6] = upper[0];	
		points[7] = lower[0];				
		
		points[8] = lower[2];
		points[9] = upper[2];
		points[10] = upper[1];
		points[11] = lower[1];		
		
		points[12] = lower[3];
		points[13] = upper[3];
		points[14] = upper[2];
		points[15] = lower[2];
		
		points[16] = lower[0];
		points[17] = upper[0];
		points[18] = upper[3];
		points[19] = lower[3];
		
		points[20] = upper[0];
		points[21] = upper[1];
		points[22] = upper[2];
		points[23] = upper[3];
              
		int[] stripCounts = new int[6];
		stripCounts[0] = 4;
		stripCounts[1] = 4;
		stripCounts[2] = 4;
		stripCounts[3] = 4;
		stripCounts[4] = 4;
		stripCounts[5] = 4;
		
		int[] contourCount = new int[6];
		for(int i=0;i<6;i++)
			contourCount[i] = 1;		     
		
		GeometryInfo gInf = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);

		gInf.setCoordinates(points);
		gInf.setStripCounts(stripCounts);
		gInf.setContourCounts(contourCount);
		
		NormalGenerator ng = new NormalGenerator();
		ng.setCreaseAngle((float) Math.toRadians(45));
		ng.generateNormals(gInf);
		this.setGeometry(gInf.getGeometryArray());     					
	}
	
}
